package com.zh.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.zh.model.User;
import com.zh.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/page")
	public String page() {
		return "user";
	}

	
	/*/user/add*/
	@RequestMapping("/add")
	@ResponseBody
	public String add(User user) {
		userService.add(user);
		return "success";
	}
	
	@RequestMapping("/del")
	@ResponseBody
	public String del(User user) {
		userService.del(user.getId());
		return "success";
		
	}
	
	@RequestMapping("/query")
	@ResponseBody
	public String query(User user) {
		List list = userService.query(user);
		JSONObject json = new JSONObject();
		json.put("result", list);
		return json.toJSONString();
		
	}
	
	@RequestMapping("/mod")
	@ResponseBody
	public String mod(User user) {
		userService.mod(user);
		return "success";
		
	}
	
}
